import { BIAN_PAGINATION_CONFIG } from '../../../../../lib/page_handler/platform/bian/types'
import { HOSTNAME, SUPPORTED_PLATFORMS } from '../../../../../types/constants'
import { IPaginationLoadType } from '../index'
import { AutoPaginationBase } from './base'

export class AutoPaginationBian extends AutoPaginationBase {
  // @Decorators.Identity
  readonly name: string = 'AutoPaginationBian'
  // @Decorators.PublicState
  private static instance: AutoPaginationBian
  // @Decorators.Config
  readonly loadType: IPaginationLoadType = IPaginationLoadType.Pagination

  /**
   * 获取单例实例
   */
  public static getInstance(): AutoPaginationBian {
    if (!AutoPaginationBian.instance) {
      AutoPaginationBian.instance = new AutoPaginationBian()
    }
    return AutoPaginationBian.instance
  }

  /**
   * 检查页面
   */
  checkPage(): boolean {
    return HOSTNAME === SUPPORTED_PLATFORMS.BIAN
  }

  /**
   * 从分页元素中获取最大页码数
   */
  getMaxPageNumFromPagination(): number {
    return this.clacMaxPageNum(BIAN_PAGINATION_CONFIG.selector.item)
  }
}
